<?php

namespace App\Http\Controllers;

use App\Http\Resources\ProductResource;
use App\Laravue\Models\productLine;
use Dotenv\Validator;
use Illuminate\Http\Request;

class productLineController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        return ProductResource::collection(productLine::all());
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //

        $validator = \Illuminate\Support\Facades\Validator::make(
            $request->all(),
            [
                'name' => ['required']
            ]
        );

        if ($validator->fails()) {
            return response()->json(['errors' => $validator->errors()], 403);
        } else {
            $params = $request->all();
            $result = productLine::updateOrCreate(['id'=>$request->input('id')],[
                'name' => $params['name'],
                'parent_id' => 0,
                'fk_type' => 0,
            ]);

            return new ProductResource($result);
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Laravue\Models\productLine  $productLine
     * @return \Illuminate\Http\Response
     */
    public function show(productLine $productLine)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Laravue\Models\productLine  $productLine
     * @return \Illuminate\Http\Response
     */
    public function edit(productLine $productLine)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Laravue\Models\productLine  $productLine
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, productLine $productLine)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Laravue\Models\productLine  $productLine
     * @return \Illuminate\Http\Response
     */
    public function destroy(productLine $productLine)
    {
        //
    }
}
